﻿#include "panel.h"
#include "ui_panel.h"

Panel::Panel(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Panel)
{
    ui->setupUi(this);

    note=nullptr;
    memo=nullptr;
    favorite=nullptr;
    todo=nullptr;
    journal=nullptr;
    toolbox=nullptr;
    searchbox=nullptr;
}

Panel::~Panel()
{
    delete ui;
}

void Panel::createTray()
{
    trayMenu=new QMenu(this);
    trayMenu->addAction(QStringLiteral("退出"),&QApplication::quit);

    tray=new QSystemTrayIcon(this);
    tray->setIcon(QIcon(":/android.ico"));
    tray->setContextMenu(trayMenu);

    connect(tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this,SLOT(trayActivated(QSystemTrayIcon::ActivationReason))
            );
    tray->show();
}

void Panel::trayActivated(QSystemTrayIcon::ActivationReason reason)
{
    if(reason == QSystemTrayIcon::DoubleClick)
        detectVisible();
}

void Panel::detectVisible()
{
    if(isVisible())
        hide();
    else
        show();
}

void Panel::on_btn_search_clicked()
{
    if(searchbox == nullptr)
        searchbox=new Searchbox(this);
    searchbox->show();
}
